<!DOCTYPE html>
<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/cookie.js"></script>
    <style>
        .layui-btn+.layui-btn{
            margin-left: 0;
        }
        .layui-table td, .layui-table th
        {
            min-width: 50px !important;
        }
    </style>
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>{$nav}</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3" style="line-height:30px"></i></a>
    </div>
    <div class="x-body x-admin">
        
      <xblock style="display: none;">
        
        <div class="layui-card-body" style="padding-left: 0;float:left;padding-left:20px;padding-top:0;">
          <form class="layui-form layui-col-space5" action="" method="get">
            <div class="layui-inline layui-show-xs-block">
              <input style="width:260px;" type="text" name="keyword" id="keyword" value="{:input()['keyword']}" placeholder="活动名称，地点，手机号" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-inline layui-show-xs-block">
              <button class="layui-btn" id="search-btn">搜索</button>
            </div>
          </form>
        </div>
      </xblock>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
          <legend>业绩PK</legend>
        </fieldset>
      <div class="layui-table-body layui-table-main" style="width: 100%;min-height:0;">
        <table class="layui-table layui-form" lay-filter="dataTabel" id="dataTabel"> </table>
      </div>

    </div>

    <script type="text/html" id="barDemo">
    
      <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">PK战况</a>
      {if session('group_id','','admin') == 1}
      <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
      {/if}
    </script>
    <script type="text/html" id="toolbarDemo">
    {if session('group_id','','admin') == 1}
      <div class="layui-btn-container">
        <button class="layui-btn" onclick="x_admin_show('添加PK活动','{:url('race/edit')}','','650','750')">添加PK活动</button>
      </div>
    {/if}
    </script>
    <script>
      layui.use(['form','layer','jquery','table','util'], function(){
        form = layui.form,
        layer = layui.layer
        ,$ = layui.jquery
        ,table = layui.table
        ,util = layui.util;
        
          table.render({
            elem: '#dataTabel'
            ,url:'{:url('admin/race/index')}?keyword={:input()['keyword']}'
            ,toolbar: '#toolbarDemo' 
            ,defaultToolbar: []//['filter', 'exports', 'print']
            ,limit: 50
            ,title: '业绩PK'
            ,cols: [[
              {field:'id', width:70, sort: true,title:"编号"},
              {field:'title', title:"活动标题"},
              {field:'start_date', width:100,title:"开始日期"},
              {field:'end_date', width:100,title:"结束日期"},
              {field:'race_type',width:80,title:"PK类型"},
              {field:'race_system', width:110,title:"能否与公司PK"},
              //{field:'race_system_min_value', width:150,title:"与公司PK最少业绩"},
              {fixed: 'right', width:200,title:"操作",  toolbar: '#barDemo'},
            ]]
            ,page: true
          });

          table.on('edit(dataTabel)', function(obj){
            var value = obj.value 
            ,data = obj.data 
            ,field = obj.field;
            console.log(obj);
            $.post('{:url('race/liveDetailEdit')}',{id:data.id, field:field,value:value},function(obj){
                layer.msg(obj.msg);
            },'json');
            
            //layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改值为：'+ util.escape(value));
          });
          
          table.on('tool(dataTabel)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
              layer.confirm('确认要删除吗？',function(index){
                  $.ajax({
                    type:'POST',
                    dataType:'json',
                    data:{id:data.id},
                    url:"{:url('race/del')}",
                    success:function(o){
                      layer.msg(o.msg,{icon:o.icon,time:1000});
                      obj.del();
                    }
                  });
              });
            } else if(obj.event === 'edit'){
              x_admin_show('编辑','{:url('race/edit')}?id='+data.id,'','650','750')
            } else if(obj.event === 'detail'){
              x_admin_show('查看详情','{:url('race/race_detail')}?race_id='+data.id)
            }
          });
          
          table.on('tool(liveDetail)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
              layer.confirm('确认要删除吗？',function(index){
                  $.ajax({
                    type:'POST',
                    dataType:'json',
                    data:{id:data.id},
                    url:"{:url('dataTable/liveDetailDel')}",
                    success:function(o){
                      layer.msg(o.msg,{icon:o.icon,time:1000});
                      obj.del();
                    }
                  });
              });
            } else if(obj.event === 'edit'){
              x_admin_show('查看详情','{:url('race/edit')}/id/'+data.id,'','650','750')
            }
          });
          form.on('submit(check)', function(data){
            var id = $(this).attr('lay-id');
            layer.confirm('是否已核对完成？', {icon: 3, title:'核对操作'}, function(index){
                $.ajax({
                    type:'POST',
                    dataType:'json',
                    data:{id:id},
                    url:"{:url('liveCheck')}",
                    success:function(obj){
                      
                      layer.msg(obj.msg, {icon: obj.icon,time: 2000},function(){
                        location.reload();
                      });
                    }
                });
              layer.close(index);
            });
            return false;
        });
      });

    </script>
  </body>

</html>